package database

import (
	"fmt"
	"github.com/go-redis/redis"
	"log"
	"micro.user.auth.server/config"
)

var redisClient *redis.Client

func InitRedis() {
	client := redis.NewClient(
		&redis.Options{
			Addr:     fmt.Sprintf("%s:%d", config.GConf.Redis.Host, config.GConf.Redis.Port),
			Password: "",
			DB:       config.GConf.Redis.DB,
		},
	)

	_, err := client.Ping().Result()
	if err != nil {
		panic("redis content error:" + fmt.Sprintf("%s", err))
	}
	log.Printf("redis content success")

	redisClient = client
}

func GetRedis() *redis.Client {
	return redisClient
}

func CloseRedis() {
	redisClient.Close()
}
